import express from 'express';
import * as shopController from './shop.conteroller';
import { fileInterceptor, fileProcessor } from './shop.middleware';
import { validateLoginData, authGuard, userGuard } from '../auth/auth.middleware';

const router = express.Router();

/**
 * 获取内容
 */
router.get('/shop', shopController.index);

/**
 * 获取内容(按 ID)
 */
router.get('/shop/:postId', userGuard, shopController.shopDetail);

/**
 * 按关键字查询（模糊查询）
 */
router.get('/getShopByKey', shopController.selectByKey);

/**
 * 创建内容
 */
router.post('/shop', shopController.store);

/**
 * 更新内容
 */
router.patch('/shop/:postId', shopController.update)

/**
 * 删除内容
 */
router.delete('/shop/:postId', authGuard, shopController.destroy);
router.post('/shopDestroy', authGuard, shopController.destroy);

/**
 * 修改状态
 */
router.patch('/shopStatus', shopController.status);

/**
 * 上传文件
 */
router.post('/shopFiles', fileInterceptor, fileProcessor, shopController.uploads);

/**
 * 文件服务
 */
router.get('/shopFiles/:fileId/serve', shopController.serve);

/**
 * 获取文件 ID
 */
router.post('/getShopFilesId', shopController.getFileName)

/**
 * 导出路由
 */
export default router;
